package com.eleventwelve.iris.web.controller;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.opentides.bean.SystemCodes;
import org.opentides.controller.BaseCrudController;
import org.opentides.editor.BaseEntityEditor;
import org.opentides.service.SystemCodesService;
import org.springframework.web.bind.ServletRequestDataBinder;

import com.eleventwelve.iris.entity.Staff;

/**
 * 
 * @author Ashley
 *
 */
public class StaffAdminController extends BaseCrudController<Staff>{
	
	@Override
	protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		
		List<SystemCodes> genders = ((SystemCodesService) getSystemCodesService()).findSystemCodesByCategory("GENDER");
		System.out.println(genders);
		Collections.reverse(genders);
		map.put("genders", genders);
		
		List<SystemCodes> staffs = ((SystemCodesService) getSystemCodesService()).findSystemCodesByCategory("STAFF_TYPE");
		System.out.println(staffs);
		Collections.reverse(staffs);
		map.put("staffs", staffs);
		
		return map;
	}
	
	@Override
	protected void initBinder(HttpServletRequest request,
		ServletRequestDataBinder binder) throws Exception {
		binder.registerCustomEditor(SystemCodes.class, new BaseEntityEditor(getSystemCodesService()));
	}
	
}
